﻿using System;
using RedBit.OAuthLibrary;

namespace TradeMeSDK
{
    /// <summary>
    /// All Membership calls do not require authentication
    /// </summary>
    public class TradeMeMembership
    {
        public void DownloadMemberProfile(int memberId, Action<BaseEventArgs<MemberProfile>> callback)
        {
            string url = TradeMeConstants.MembershipUrl + memberId + "/Profile.json";
            WebHelper.DownloadAndParse(url, callback);
        }

        public void DownloadMemberFeedback(int memberId, Action<BaseEventArgs<Feedback>> callback)
        {
            string url = TradeMeConstants.MembershipUrl + memberId + "/Feedback.json";
            WebHelper.DownloadAndParse(url, callback);
        }

        public void DownloadMemberSellingFeedback(int memberId, Action<BaseEventArgs<Feedback>> callback)
        {
            string url = TradeMeConstants.MembershipUrl + memberId + "/Feedback/selling.json";
            WebHelper.DownloadAndParse(url, callback);
        }

        public void DownloadMemberBuyingFeedback(int memberId, Action<BaseEventArgs<Feedback>> callback)
        {
            string url = TradeMeConstants.MembershipUrl + memberId + "/Feedback/buying.json";
            WebHelper.DownloadAndParse(url, callback);
        }

        /// <summary>
        /// Returns feedback summary for a specified Trade Me member
        /// </summary>
        public void DownloadMemberFeedbackCount(int memberId, Action<BaseEventArgs<FeedbackCount>> callback)
        {
            string url = TradeMeConstants.MembershipUrl + memberId + "/FeedbackCount.json";
            WebHelper.DownloadAndParse(url, callback);
        }

        /// <summary>
        /// Returns the current listings for a seller. Provides data similar to that on the ‘Seller’s other listings’ 
        /// page on the Trade Me website.
        /// </summary>
        public void DownloadMemberListings(int memberId, Action<BaseEventArgs<Listings>> callback)
        {
            string url = TradeMeConstants.MembershipUrl + memberId + "/Listings/All.xml";
            WebHelper.DownloadAndParse(url, callback);
        }

        public void DownloadMemberId(string memberNickname, Action<BaseEventArgs<MemberId>> callback)
        {
            string url = TradeMeConstants.MembershipUrl + memberNickname + ".json";
            WebHelper.DownloadAndParse(url, callback);
        }
    }
}